<?php
namespace app\index\controller;
use think\Controller;
use think\Log;
use think\Db;
use think\Config;
use think\Url;
use think\Request;
class Index extends Base
{


    public function index()
    {

        switch ($_SERVER['REQUEST_METHOD']) {
            case "POST": {

                $passwd  = $_POST['passwd'];
                $phone   = $_POST['phone'];
                $where['phone'] = $phone;
                $this->validParam($phone, 'phone');

                if (!($this->user = Db::name('user')->where($where)->find())) $this->error('该用户不存在！');

                if ($this->user['status'] == 1) {
                    $this->error('您的账户被暂时冻结。如需解冻请联系赵扬大牛');
                }

                $pwd = $this->getPwd($passwd);
                if ($pwd != $this->user['passwd']) {
                    $this->error('用户名或密码错误');
                }

                $this->setCookie($this->user);
                $this->success('登录成功','/index/user/index');
                break;
            }
            case "GET": {
                return $this->fetch();
            }
            default: {
                $this->error('请求方式错误');
                break;
            }
        }
        return $this->fetch();
    }


    //文件上传提交
    public function upload()
    {


        //获取表单上传文件
        $file = request()->file("files");


        if (!isset($file)) {
            $this->error('请选择上传文件');
        }

        $user_no = '333';
        $daytime  = date("Ymd");
        //移动到框架应用根目录/public/uploads/ 目录下
        $path = ROOT_PATH.'public/uploads/'.$user_no.'/'.$daytime;


        if(!is_dir($path)){
            mkdir($path,0777,true);
        }


        $info = $file->move(ROOT_PATH . 'public/uploads/'.$user_no.'/'.$daytime,'dd');

        if ($info) {
            $this->success('文件上传成功');
            echo $info->getFilename();
        } else {
            //上传失败获取错误信息
            $this->error($file->getError());
        }
    }

}
